<?php

namespace app\api\controller;

use app\api\service\WechatappService;

class Wechatapp extends CommonController
{
    protected $wxapp;

    public function __construct()
    {
        parent::__construct();
        $this->wxapp = WechatappService::getApp();

    }

    /**
     * @desc 获取session_key和openid
     * @return \think\response\Json
     * @throws \app\common\exception\HttpCode
     */
    public function auth()
    {
        $data = WechatappService::session($this->request['code']);

        return $this->success($data);
    }

    /**
     * @desc 登录
     * @return \think\response\Json
     * @throws \app\common\exception\HttpCode
     */
    public function login()
    {
        $token = WechatappService::login($this->request);
        $data['token'] = $token;
        return $this->success($data);
    }
}
